/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package converter;


import entities.Event;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.ConverterException;
import javax.faces.convert.FacesConverter;

/**
 *
 * @author Chien
 */
@FacesConverter(forClass=Event.class)
public class EventConverter implements javax.faces.convert.Converter{

    private Event users;
    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        if (users == null) {
            users = new Event(value);
            return users;
        } else {
            throw new ConverterException(new FacesMessage(String.format("Can not convert %s to Event", value)));
        }
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        return String.valueOf(((Event)value).getEventId());
    }
    
}
